import java.util.Arrays;

public class _76最小覆盖子串 {
    public static String minWindow(String s, String t) {
        int[] tArr=new int[52];
        for (char i : t.toCharArray()) {
            tArr[i-'A']++;
        }
        int diff=-1;
        int start=0;
        int end=0;
        //求s的区间start and end
        char[] sArray = s.toCharArray();
        for (int i = 0; i < s.length(); i++) {
            int[] arr=new int[52];
            for (int j = i; j < s.length(); j++) {
                arr[sArray[j]-'A']++;
                if(Arrays.equals(tArr, arr)){
                    int substract = j-i;
                    if(diff==-1){
                        diff=substract;
                        start=i;
                        end=j;
                    }else{
                        diff=Math.min(diff, substract);
                        if(substract<diff){
                            start=i;
                            end=j; 
                        }
                    }
                    break;
                }
            }
        }
        char[] copyOfRange = Arrays.copyOfRange(s.toCharArray(),start,end);;

        return new String(copyOfRange);

    }

    public static void main(String[] args) {
        System.out.println(minWindow("ADOBECODEBANC", "abcABC"));
    }
}
